package weaver.interfaces.zhlx.duss.action.salesmodule.c4;

import com.alibaba.fastjson.JSONObject;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.interfaces.zhlx.duss.utils.C4Util;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2023-11-27
 * @Description: 报价单流程归档节点前审批结果回传C4, 反写报价单审批状态接口
 * @ModifyLog:
 **/
public class WeaBjdlcBackAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        String src = requestInfo.getRequestManager().getSrc();
        writeLog(">>>>>WeaBjdlcBackAction>>>>>requestid=" + requestid);
        try {
            String message = "调用C4系统接口返回:";
            String uuid = Util.null2String(C4Util.getUUIDByWf(tablename, requestid));
            JSONObject paramJson = new JSONObject();
            if ("reject".equals(src)) {
                paramJson.put("Z_QuoteApproveStatus_KUT", "131");
            } else {
                paramJson.put("Z_QuoteApproveStatus_KUT", "121");
            }
            Map<String, Object> dataMap = new HashMap<>();
            dataMap.put("jkdymc", "WeaBjdlcBackAction");
            dataMap.put("lcid", requestid);
            dataMap.put("dylc", requestid);
            dataMap.put("uuid", uuid);
            writeLog(">>>>>WeaBjdlcBackAction>>>>>paramJson=" + paramJson);
            JSONObject resultJson = C4Util.updateBjdStatus(paramJson, dataMap);
            writeLog(">>>>>WeaBjdlcBackAction>>>>>resultJson=" + resultJson);
            String code = Util.null2String(resultJson.getString("code"));
            if (!"success".equals(code)) {
                message += Util.null2String(resultJson.getString("message"));
                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent(message);
                return Action.FAILURE_AND_CONTINUE;
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            writeLog(">>>>>WeaBjdlcBackAction>>>>>Exception=" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口处理异常,请联系管理员");
            return Action.FAILURE_AND_CONTINUE;
        }
    }


}